var autoSearch;
var showDetails;
var ylDialog;
var jlDialog;
var szDialog;
require(['grid', 'topBar', 'layout','date'], function () {
    $('body').layout();
    $('#top').topBar({
        left: [{
                   type: 'filter-more',
			       dateType:'custom',
                   search: function () {
	                	// 左侧树tab选中的类型
	   					var type = commonFun.getLeftTreeCurrentTreeType();
	   					var orgIds = commonFun.getLeftTreeCheckedNodes(type); 
//	   					var orgIds = "aa0a1f73350e42158b559299052e9234";
	   					if(type != 'CAR'){
	   						$.messager.alert("提示","请切换到车辆。","info");
	   					}else if(!orgIds){
	   						$.messager.alert("提示","请选择查询车辆。","info");
	   					}else{
	   	                	var postData = $(this).getValues();
	   	                	postData.orgIds=orgIds;
	   	                	postData.logType="'ULOG0009'";
	   						$('#grid').grid('setGridParam', {
								page : 1,
								datatype : "json",
								postData : postData
							}).trigger("reloadGrid");
	   					}                	   
                   },
                   item: [
                       {
                           text: '时间快捷',
                           name1: 'beginTime',
                           name2: 'endTime',
                           type: 'dateLine'
                       }
                   ]
               }]
    });

    $('#grid').grid({
    	url : "/airConditioner/searchAirMonitorLogPage.htm",
		multiselect:false,
		colModel:[
			{name: "licPltNo", label:"车牌号"},
			{name: "eqmtCd", label:"设备ID"},
			{name: "upgradeBeginTime", label:"设置开始时间"},
			{name: "upgradeEndTime", label:"设置结束时间"},
			{
				name: "vrsnName",
				label: '设置模版名称',
				formatter: function (cellvalue, options, rowObject) {
					return '<a onclick="showDetails(\'{0}\',\'{1}\')">{2}</a>'.format(rowObject.vrsnId, rowObject.vrsnType,rowObject.vrsnName);
				}
			},
			{name: "vrsnId", label:"vrsnId",hidden: true},
			{name: "vrsnType", label:"vrsnType",hidden: true},
			{name: "upgradeSt", label:"设置状态", dict:"UPST0000"},
			{name: "stMsg", label:"状态消息", dict:"UPSM0000"},
			{name: "upgradeUser",label:"设置用户"}]
    });

	autoSearch=function(){
		$("a[data-val='01']","#top").click();
	}

	function getDialog(vrsnType){
		if(vrsnType=="VERS0007") {//银隆
			if (!ylDialog) {
				ylDialog = $('<div>').dialog({
					url: './mainte/setting/TemplateAirConditioEdit_yl.htm',
					height: 480,
					width: 720,
					close: function () {
						ylDialog.dialog('exec', 'reset', true);
					},
					buttons: [
						{
							text: '关闭',
							css: 'btn-cancel',
							click: function () {
								$(this).dialog('close');
							}
						}
					]
				});
			}
			return ylDialog;
		}
		else if(vrsnType=="VERS0008") {//金旅
			if (!jlDialog) {
				jlDialog = $('<div>').dialog({
					url: './mainte/setting/TemplateAirConditioEdit_jl.htm',
					height: 480,
					width: 720,
					close: function () {
						ylDialog.dialog('exec', 'reset', true);
					},
					buttons: [
						{
							text: '关闭',
							css: 'btn-cancel',
							click: function () {
								$(this).dialog('close');
							}
						}
					]
				});
			}
			return jlDialog;
		}
		else {
			if (!szDialog) {
				szDialog = $('<div>').dialog({
					url: './mainte/setting/TemplateAirConditioEdit_sz.htm',
					height: 480,
					width: 720,
					close: function () {
						ylDialog.dialog('exec', 'reset', true);
					},
					buttons: [
						{
							text: '关闭',
							css: 'btn-cancel',
							click: function () {
								$(this).dialog('close');
							}
						}
					]
				});
			}
			return szDialog;
		}
	}

	showDetails=function(vrsnId,vrsnType){
		var dialog=getDialog(vrsnType);
		dialog.dialog('setOption', 'title',"空调参数");
		dialog.dialog('exec', 'reload', vrsnId);
		dialog.dialog('open');
	}

})
